/*     */ package com.zimbra.qa.unittest.prov.ldap;
/*     */ 
/*     */ import com.zimbra.common.account.Key.ServerBy;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.qa.unittest.prov.Names;
/*     */ import com.zimbra.soap.admin.type.CacheEntryType;
/*     */ import java.util.HashMap;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestLdapProvServer
/*     */   extends LdapTest
/*     */ {
/*     */   private static LdapProvTestUtil provUtil;
/*     */   private static Provisioning prov;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  41 */     provUtil = new LdapProvTestUtil();
/*  42 */     prov = provUtil.getProv();
/*     */   }
/*     */   
/*     */   private Server createServer(String serverName) throws Exception {
/*  46 */     return provUtil.createServer(serverName, null);
/*     */   }
/*     */   
/*     */   private Server createServer(String serverName, Map<String, Object> attrs) throws Exception {
/*  50 */     return provUtil.createServer(serverName, attrs);
/*     */   }
/*     */   
/*     */   private void deleteServer(Server server) throws Exception {
/*  54 */     provUtil.deleteServer(server);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void createServer() throws Exception {
/*  59 */     String SERVER_NAME = Names.makeServerName(genServerName());
/*  60 */     Server server = createServer(SERVER_NAME);
/*  61 */     deleteServer(server);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void createServerAlreadyExists() throws Exception {
/*  66 */     String SERVER_NAME = Names.makeServerName(genServerName());
/*  67 */     Server server = createServer(SERVER_NAME);
/*     */     
/*  69 */     boolean caughtException = false;
/*     */     try {
/*  71 */       prov.createServer(SERVER_NAME, new HashMap());
/*     */     } catch (AccountServiceException e) {
/*  73 */       if ("account.SERVER_EXISTS".equals(e.getCode())) {
/*  74 */         caughtException = true;
/*     */       }
/*     */     }
/*  77 */     Assert.assertTrue(caughtException);
/*     */     
/*  79 */     deleteServer(server);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void localServer() throws Exception {
/*  84 */     Server localServer = prov.getLocalServer();
/*  85 */     Assert.assertNotNull(localServer);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getAllServers() throws Exception {
/*  90 */     String SERVER_NAME_1 = Names.makeServerName(genServerName("1"));
/*     */     
/*  92 */     Map<String, Object> server1Attrs = new HashMap();
/*  93 */     server1Attrs.put("zimbraServiceEnabled", new String[] { "memcached", "mailbox" });
/*     */     
/*  95 */     Server server1 = createServer(SERVER_NAME_1, server1Attrs);
/*     */     
/*  97 */     String SERVER_NAME_2 = Names.makeServerName(genServerName("2"));
/*  98 */     Server server2 = createServer(SERVER_NAME_2);
/*     */     
/* 100 */     List<Server> allServers = prov.getAllServers();
/* 101 */     Assert.assertEquals(3L, allServers.size());
/*     */     
/* 103 */     Set<String> allServerIds = new HashSet();
/* 104 */     for (Server server : allServers) {
/* 105 */       allServerIds.add(server.getId());
/*     */     }
/* 107 */     Assert.assertTrue(allServerIds.contains(prov.getLocalServer().getId()));
/* 108 */     Assert.assertTrue(allServerIds.contains(server1.getId()));
/* 109 */     Assert.assertTrue(allServerIds.contains(server2.getId()));
/*     */     
/* 111 */     List<Server> allServersByService = prov.getAllServers("memcached");
/* 112 */     Assert.assertEquals(1L, allServersByService.size());
/* 113 */     Assert.assertEquals(server1.getId(), ((Server)allServersByService.get(0)).getId());
/*     */     
/* 115 */     deleteServer(server1);
/* 116 */     deleteServer(server2);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getServer() throws Exception {
/* 121 */     String SERVER_NAME = Names.makeServerName(genServerName());
/* 122 */     Server server = createServer(SERVER_NAME);
/* 123 */     String serverId = server.getId();
/*     */     
/* 125 */     prov.flushCache(CacheEntryType.server, null);
/* 126 */     server = prov.get(Key.ServerBy.id, serverId);
/* 127 */     Assert.assertEquals(serverId, server.getId());
/*     */     
/* 129 */     prov.flushCache(CacheEntryType.server, null);
/* 130 */     server = prov.get(Key.ServerBy.name, SERVER_NAME);
/* 131 */     Assert.assertEquals(serverId, server.getId());
/*     */     
/* 133 */     deleteServer(server);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getServerNotExist() throws Exception {
/* 138 */     String SERVER_NAME = Names.makeServerName(genServerName());
/* 139 */     Server server = prov.get(Key.ServerBy.name, SERVER_NAME);
/* 140 */     Assert.assertNull(server);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/ldap/TestLdapProvServer.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */